package http_proxy_router

import (
	"go-gateway-learn/controller"
	httpproxymiddleware "go-gateway-learn/httpproxymiddleware"
	"go-gateway-learn/middleware"

	"github.com/gin-gonic/gin"
)

func InitRouter(middlewares ...gin.HandlerFunc) *gin.Engine {
	// router := gin.Default()
	router := gin.New()
	router.Use(middlewares...)
	router.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pinged was successful!",
		})
	})

	oauth := router.Group("/oauth")
	oauth.Use(middleware.TranslationMiddleware())
	{
		controller.OAuthRegister(oauth)
	}

	router.Use(httpproxymiddleware.HTTPAccessModeMiddleware(),
	
			httpproxymiddleware.HTTPFlowCountMiddleware(),
			httpproxymiddleware.HTTPFlowLimitMiddleware(),

			httpproxymiddleware.HTTPJWTOAuthTokenMiddleware(),
			httpproxymiddleware.HTTPJwtFlowCountMiddleware(),
			httpproxymiddleware.HTTPJwtFlowLimitMiddleware(),

			httpproxymiddleware.HTTPWhiteIPListMiddleware(),
			httpproxymiddleware.HTTPBlackIPListMiddleware(),

			httpproxymiddleware.HTTPHeaderTransferMiddleware(),
			httpproxymiddleware.HTTPStripUriMiddleware(),
			httpproxymiddleware.HTTPUrlRewriteMiddleware(),

			httpproxymiddleware.HTTPReverseProxyMiddleware())
	
	return router
}
